package com.zcgame.base.utils

import android.annotation.SuppressLint
import android.content.Context
import android.provider.Settings
import android.telephony.TelephonyManager
import android.text.TextUtils

/**
 *@author:huangLJ
 *@date:2021/5/27 18:14
 */
object JniUtils {
    private val sb = StringBuffer()
    private val map = intArrayOf(69, 72, 110, 120, 73, 101, 110, 77, 104, 90, 76, 74, 86, 115, 53, 48)

    var key:String = ""
        get() {
            map.forEach {
                sb.append(it)
            }
            return sb.toString()
        }
    private set

    /**
     * 拿IMEI，如果没有就拿默认值
     * return：IMEI
     */
    fun getIMEI(context: Context):String{
        var imei = ""
        try {
            imei = getIdfa(context)
        }catch (e:Exception){
            e.printStackTrace()
        }
        if(TextUtils.isEmpty(imei)){
            imei = "FFFFFFFFFFFFFFF"
        }
        return imei
    }

    /**
     * 获取IMEI或者Android
     */
    @SuppressLint("HardwareIds")
    private fun getIdfa(context: Context): String {
        var idfa = "";
        try {
            //获取IMEI
            val tel = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
            //idfa = tel.deviceId
        }catch (e:Exception){
            e.printStackTrace()
        }
        if(TextUtils.isEmpty(idfa)){
            //获取Android ID
            idfa = Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID)
        }
        return idfa
    }

    /**
     * 获取OAID
     */
    fun getOAID(context: Context): String {
        return getOAID(context)
    }


}